package com.mad.base.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import com.mad.base.objects.grid.FieldCoverer;
import com.mad.base.objects.grid.FieldMarker;
import com.mad.base.system.ID;


public class MADPanel extends JPanel implements MouseListener{

	private static final long serialVersionUID = 1L;

	private ID id ; 
	private FieldCoverer fieldCoverer; 
	private FieldMarker fieldMarker ; 
	
	public FieldCoverer getFieldCoverer()
    {
        return fieldCoverer;
    }

    public FieldMarker getFieldMarker()
    {
        return fieldMarker;
    }

    public MADPanel(ID id){
		this.setId(id);
		this.fieldCoverer = new FieldCoverer(); 
		this.fieldMarker = new FieldMarker(); 
		this.addMouseListener(this); 
		this.setBorder(BorderFactory.createLineBorder(Color.black)); 
		this.setBackground(Color.LIGHT_GRAY); 
	}

	public ID getId() {
		return id;
	}

	public void setId(ID id) {
		if (!(id == null))
			this.id = id;
	}

	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		if(this.fieldCoverer.isCovered())
		    this.setBackground( Color.red ); 
		g.drawString(id.toString(), this.getWidth() / 4, this.getHeight() / 2);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.println(id+" has been clicked :) ");
	}  

	@Override
	public void mousePressed(MouseEvent e) {
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		this.setBackground(Color.GRAY); 	
	}

	@Override
	public void mouseExited(MouseEvent e) {
		this.setBackground(Color.LIGHT_GRAY); 
	}

}
